#!/bin/bash

#################
# WMDRM script.
# This script prepare the environment before running the 
# WMDRM test case. It copies the relevant files to be located
# under the `/nfsroot` root folder - this is the WMDRM
# root refernce on the Linux target machin.
# It performs the following:
#  1. Delete (if exist) `samples`, `Source` and `Test` folders under `/nfsroot`
#  2. Copy the `samples`, `Source` and `Test` files from the `/HostPackage` into `/nfsroot`
#  3. Creates `WMDRMPD` folder under `/nfsroot`
#  
# NOTE: The `/nfsroot/WMDRMPD/` folder is empty. 
#       Before running any WMDRM test you MUST copy the following stuff
#       to be located under that folder:
#       1. devcert.dat  -This is the device certificate, derive from the device certificate template.
#       2. devcerttemplate.dat -This is the device certificate template.
#       3. priv.dat - This is the device private key.
#       IMPORTANT: In case you don't have this files under, you may copy them manually 
#       from `/HostPackage/WMDRM/Samples/`
#

###paths are case sensitive
d_src=../../../
d_root=/nfsroot

d_wmdrm=WMDRM
d_dst_samples=samples
d_src_samples=Samples
d_source=Source
d_test=Test
d_wmdrmpd=WMDRMPD

###params check
if [ ! -d $d_root ]; then
  echo "'" $d_root "' No such directory, exiting..."
  exit 1
fi
if [ ! -d $d_src/$d_wmdrm/$d_src_samples ]; then
  echo "'" $d_src/$d_wmdrm/$d_src_samples "' No such directory, exiting..."
  exit 1
fi
if [ ! -d $d_src/$d_wmdrm/$d_source ]; then
  echo "'" $d_src/$d_wmdrm/$d_source "' No such directory, exiting..."
  exit 1
fi
if [ ! -d $d_src/$d_wmdrm/$d_test ]; then
  echo "'" $d_src/$d_wmdrm/$d_test "' No such directory, exiting..."
  exit 1
fi
if [ ! -d $d_src/$d_wmdrmpd ]; then
  echo "'" $d_src/$d_wmdrmpd "' No such directory, exiting..."
  exit 1
fi


###force remove folders first
rm -rf $d_root/$d_dst_samples
rm -rf $d_root/$d_source
rm -rf $d_root/$d_test
rm -rf $d_root/$d_wmdrmpd

###copy to target
cp -r $d_src/$d_wmdrm/$d_src_samples   $d_root/$d_dst_samples
cp -r $d_src/$d_wmdrm/$d_source    $d_root/$d_source
cp -r $d_src/$d_wmdrm/$d_test      $d_root/$d_test
cp -r $d_src/$d_wmdrmpd            $d_root/$d_wmdrmpd

